package chpt08;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

public class DirTraversal{
	public static void main(String[] args) throws IOException{
		Path dir = Paths.get("/tmp");
		Files.walkFileTree(dir,new SimpleFileVisitor<Path>(){
			@Override
			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
				if (file.toString().endsWith(".java")||
						file.toString().endsWith(".class")) {
					System.out.println(file.getFileName());
				}
				return FileVisitResult.CONTINUE;
			}
		});
	}
}
